import os

import requests
#定义一个类：
class DingTalk():
    def __init__(self):
        self.url='https://oapi.dingtalk.com/robot/send?access_token=8fa098088ad40a752d31d4c3a894e7cd995a8c2a56d45237b8d3d7eaa005f644'
    def send_msg(self,text):
        dic = {"msgtype": "text",
               "text": {"content": text},
               "at": {
                   "atMobiles": ["+86-13552828809", "+86-18601916518"],
                   "isAtAll": False}}
        res=requests.post(url=self.url,json=dic)
        return res
    def send_link(self,text,url):
        dic = {
            "msgtype": "link",
            "link": {
                "text": text,
                "title": "橙好登录模块测试报告,请查收",
                "messageUrl": url
            }
        }
        res=requests.post(self.url,json=dic)
        return res
if __name__ == '__main__':
    dt=DingTalk()
    res=dt.send_msg('测试：李连营')
    print(res.text)
    # res=dt.send_link('测试：李连营','http')
    # print(res.text)
    path=os.path.dirname(os.path.dirname(__file__)) + '/testReport'
    list1=os.listdir(path)[0]
    res2=dt.send_link('测试：李连营',f'http://www.chenghao.com:8080/app/{list1}')
    print(res2.text)

